//go:build wireinject

// Package package startup
/**
* @Project : geektime-basic-go-study
* @File    : wire.go
* @IDE     : GoLand
* @Author  : Tvux
* @Date    : 2024/10/18 11:49
**/

package startup

import (
	"geektime-basic-go-study/webook/backend/internal/repository"
	article2 "geektime-basic-go-study/webook/backend/internal/repository/article"
	"geektime-basic-go-study/webook/backend/internal/repository/cache"
	"geektime-basic-go-study/webook/backend/internal/repository/dao"
	article3 "geektime-basic-go-study/webook/backend/internal/repository/dao/article"
	"geektime-basic-go-study/webook/backend/internal/service"
	"geektime-basic-go-study/webook/backend/internal/web"
	"geektime-basic-go-study/webook/backend/internal/web/article"
	ijwt "geektime-basic-go-study/webook/backend/internal/web/jwt"
	"geektime-basic-go-study/webook/backend/internal/web/oauth2"
	"geektime-basic-go-study/webook/backend/ioc"
	"github.com/gin-gonic/gin"
	"github.com/google/wire"
)

func InitWebServer() *gin.Engine {
	wire.Build(
		ioc.InitZapLogger,
		ioc.InitDB,
		ioc.InitRedis,
		dao.NewGormUserDAO,
		article3.NewGormArticleDAO,
		cache.NewRedisUserCache,
		cache.NewRedisCodeCache,
		repository.NewCachedUserRepository,
		repository.NewCachedCodeRepository,
		article2.NewCachedArticleRepository,
		service.NewUserService,
		service.NewArticleService,
		ioc.InitWechatService,
		ioc.GetSMSServices,
		ioc.InitSMSService,
		ioc.InitSMSCodeService,
		ijwt.NewRedisJWTHandler,
		web.NewUserHandler,
		oauth2.NewWechatHandler,
		article.NewHandler,
		ioc.GetMiddlewares,
		ioc.InitWebServer,
	)
	return nil
}

func InitUserHandler() *web.UserHandler {
	wire.Build(
		ioc.InitZapLogger,
		ioc.InitDB,
		ioc.InitRedis,
		dao.NewGormUserDAO,
		cache.NewRedisUserCache,
		cache.NewRedisCodeCache,
		repository.NewCachedUserRepository,
		repository.NewCachedCodeRepository,
		service.NewUserService,
		ioc.GetSMSServices,
		ioc.InitSMSService,
		ioc.InitSMSCodeService,
		ijwt.NewRedisJWTHandler,
		web.NewUserHandler,
	)
	return nil
}

var thirdProvider = wire.NewSet(
	ioc.InitZapLogger,
	ioc.InitDB,
	ioc.InitRedis,
)

func InitArticleHandler() *article.Handler {
	wire.Build(
		thirdProvider,
		article3.NewGormArticleDAO,
		article2.NewCachedArticleRepository,
		service.NewArticleService,
		article.NewHandler,
	)
	return nil
}
